package com.xuecheng.basic.controller;

import com.xuecheng.basic.domain.Category;
import com.xuecheng.commons.model.vo.CategoryVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.utils.BeanHelper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xuecheng.basic.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程分类前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService  categoryService;

    //课程分类查询

    @GetMapping("/tree-nodes")
    public ResponseResult  findTreeNodes(){
        //调用service
      return   categoryService.findTreeNodes();
    }

    /*根据id 查询分类信息
    GET     /{id}
     */
    @GetMapping("/{id}")
    public ResponseResult findById(@PathVariable("id")String id){
        Category category = categoryService.getById(id);
        CategoryVo vo = BeanHelper.copyProperties(category, CategoryVo.class);
        return ResponseResult.okResult(vo);
    }
}
